package com.lagou.edu.controller;

import com.lagou.edu.service.RegisterService;
import com.lagou.edu.service.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author bobcheng
 * @date 2020/7/2
 */
@RestController
@Slf4j
public class RegisterController {

    @Autowired
    private RegisterService registerService;
    @Autowired
    private TokenService tokenService;

    @GetMapping("/register/{email}/{password}/{code}")
    public boolean register(@PathVariable String email, @PathVariable String password, @PathVariable String code, HttpServletResponse response) {
        boolean register = registerService.register(email, password, code);
        if (register) {
            tokenService.addToken(email, response);
        }
        return register;
    }

    @GetMapping("/isRegistered/{email}")
    public boolean isRegistered(@PathVariable String email) {
        return registerService.isRegistered(email);
    }
}
